package leetCode.fourthWeek;

public class Code_74 {
  public boolean searchMatrix(int[][] matrix, int target) {
    if (matrix.length == 0
        || matrix[0].length == 0
        || matrix[0][0] > target
        || matrix[matrix.length - 1][matrix[0].length - 1] < target) {
      return false;
    }
    int line = matrix.length - 1;
    for (int i = 0; i < matrix.length; i++) { // 取出来目标行
      //      if (matrix[i][0] == target) {
      //        return true;
      //      }
      if (matrix[i][0] > target) {
        line = i - 1;
        break;
      }
    }
    for (int i = 0; i < matrix[0].length; i++) {
      if (matrix[line][i] != target) {
        continue;
      } else {
        return true;
      }
    }
    return false;
  }
}
